package com.gem.netty.service.gem;

import com.gem.entity.Game;
import com.gem.enums.ClientMessageType;
import com.gem.enums.GameRoundStageType;
import com.gem.enums.MessageColorType;
import com.gem.factory.game.GameFactory;
import com.gem.netty.entity.ClientContent;
import com.gem.netty.entity.CurrentUser;
import com.gem.pipeline.BusinessProcess;
import com.gem.pipeline.ProcessContext;
import com.gem.utils.R;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 13:48
 * 是否拿宝石回合
 */
public class IsGetGemRoundService implements BusinessProcess<ClientContent> {
    @Override
    public void process(ProcessContext<ClientContent> context) {
        Game game = GameFactory.get(context.getData().getRoomId());

        CurrentUser user = game.getUsers().get(game.getCurrentIndex());
        if (user.getState() != GameRoundStageType.GET_GEM.type){
            context.setResult(R.error().data("color", MessageColorType.SYSTEM_MESSAGE.type).type(ClientMessageType.GET_GEM.type).message("不是拿宝石回合"));
            context.setNeedBreak(true);
        }
    }
}
